package com.sinog.front.service.user;

import com.sinog.core.utilbean.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * @desc 修改密码
 * @author zy
 * @date -
 */
@Service
public class UserPwdService {

    @Value("${gkzx.azbj.auth.auth-server-url-diy}")
    private String serverUrl;
    @Autowired
    private RestTemplateBuilder builder;

    /**
     * 修改密码
     * @param account account
     * @param oldpwd oldpwd
     * @param pwd pwd
     * @return Result
     */
    public Result updatePwd(String account,String oldpwd,String pwd) {
        RestTemplate template = builder.build();
        MultiValueMap<String,String> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("account",account);
        requestEntity.add("oldpwd",oldpwd);
        requestEntity.add("pwd",pwd);
        ResponseEntity<Result> forEntity = template.postForEntity(serverUrl + "/user/password",requestEntity,Result.class);
        return forEntity.getBody();
    }

    /**
     * Oauth认证客户端更新登录用户信息
     * @param data data
     */
    public void saveAuthUser(String data) {
        RestTemplate template = builder.build();
        MultiValueMap<String,String> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("data",data);
        template.postForEntity(serverUrl + "/user/info",requestEntity,Result.class);
    }
}